// Copyright 2011 Jefferson Willian
// willmont7@gmail.com

#include <cstdio>
#include <algorithm>

#define MAX 151

using std::sort;

typedef struct Height {
  int h;
  int ind;
}Height;

int solve(Height height[], bool matriz[][MAX], int init, int n) {
  int max[MAX];

  for (int i = 0;i < n;i++)
    max[i] = 0;

  for (int i = n-2;i >= 0;i--) {
    for (int j = i+1;j < n;j++) {
      if (height[i].h == height[j].h)
        continue;
      if (matriz[height[i].ind][height[j].ind])
        if (max[j]+1 > max[i])
          max[i] = max[j]+1;
    }
    if (height[i].ind == init)
      return max[i];
  }

  return 0;
}

bool compare(Height a, Height b) {
  return a.h > b.h;
}

int main() {
  int n, m, init;
  Height height[MAX];
  bool matriz[MAX][MAX];
  int ind[MAX];
  int in[2];
  int games = 1;

  while (scanf("%d%d%d", &n, &m, &init) && (n != 0 || m != 0 || init != 0)) {
    for (int i = 0;i < n;i++)
      for (int j = 0;j < n;j++)
        matriz[i][j] = false;

    for (int i = 0;i < n;i++) {
      scanf("%d", &height[i].h);
      height[i].ind = i;
    }

    for (int i = 0;i < m;i++) {
      scanf("%d%d", &in[0], &in[1]);
      matriz[in[0]-1][in[1]-1] = true;
    }

    sort(height, height+n, compare);

    printf("Teste %d\n%d\n\n", games++, solve(height, matriz, init-1, n));
  }

  return 0;
}
